<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@include file="/WEB-INF/views/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@include file="/WEB-INF/views/include/head.jsp"%>
<link href="<%=contextPath %>/assets/hplus/css/plugins/chosen/chosen.css" rel="stylesheet">
</head>
<body style="background-color: white;" class="gray-bg">
<div class="wrapper wrapper-content animated">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form  class="form-horizontal m-t" id="signupForm">
                         <input id="id" name="id" value="${user.id }" class="form-control" type="hidden">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">用户名：</label>
                                <div class="col-sm-8">
                                    <input id="username" name="username" value="${user.username }" class="form-control" type="text">
                                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 这里写点提示的内容</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">姓名：</label>
                                <div class="col-sm-8">
                                    <input id="truename" name="truename" value="${user.truename }" class="form-control" type="text" aria-required="true" aria-invalid="false" class="valid">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">电话号码：</label>
                                <div class="col-sm-8">
                                    <input id="mobile" name="mobile" value="${user.mobile }" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">邮箱：</label>
                                <div class="col-sm-8">
                                    <input id="email" name="email" value="${user.email }" class="form-control" type="email">
                                </div>
                            </div>
                            <div class="form-group">
                            <label class="col-sm-3 control-label">拥有角色：</label>
                            <div class="col-sm-8">
                                <select id="roleIds" name="roleIds" data-placeholder="选择角色" class="chosen-select" multiple style="width:350px;" tabindex="4">
                                    <c:forEach items="${allRoleVos}" var="roleVo">
                                    	<option value="${roleVo.role.id }" ${roleVo.selected } hassubinfo="true">${roleVo.role.name }</option>
                                    </c:forEach>
                                    
                                </select>
                            </div>
                        </div>
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-3">
                                    <button class="btn btn-primary" type="submit">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>
	<%@include file="/WEB-INF/views/include/foot.jsp"%>
	
	<!-- 自定义js -->
	<script
		src="<%=contextPath%>/assets/hplus/js/content.min.js?v=1.0.0"></script>

	<!-- jQuery Validation plugin javascript-->
	<script
		src="<%=contextPath%>/js/jquery.form.js"></script>
	<script
		src="<%=contextPath%>/assets/hplus/js/plugins/validate/jquery.validate.min.js"></script>
	<script
		src="<%=contextPath%>/assets/hplus/js/plugins/validate/messages_zh.min.js"></script>
	 <!-- Chosen -->
    <script src="<%=contextPath%>/assets/hplus/js/plugins/chosen/chosen.jquery.js"></script>
	<script>
		$.validator.setDefaults({
			highlight : function(a) {
				$(a).closest(".form-group").removeClass("has-success")
						.addClass("has-error")
			},
			success : function(a) {
				a.closest(".form-group").removeClass("has-error").addClass(
						"has-success")
			},
			errorElement : "span",
			errorPlacement : function(a, b) {
				if (b.is(":radio") || b.is(":checkbox")) {
					a.appendTo(b.parent().parent().parent())
				} else {
					a.appendTo(b.parent())
				}
			},
			errorClass : "help-block m-b-none",
			validClass : "help-block m-b-none"
		});
		var index = parent.layer.getFrameIndex(window.name);
		$().ready(function() {
			var config = {
					".chosen-select" : {},
					".chosen-select-deselect" : {
						allow_single_deselect : true
					},
					".chosen-select-no-single" : {
						disable_search_threshold : 10
					},
					".chosen-select-no-results" : {
						no_results_text : "Oops, nothing found!"
					},
					".chosen-select-width" : {
						width : "95%"
					}
				};
				for ( var selector in config) {
					$(selector).chosen(config[selector])
				}
			
			$("#commentForm").validate();
			var a = "<i class='fa fa-times-circle'></i> ";
			$("#signupForm").validate({
				rules : {
					username : {
						required : true,
						minlength : 2
					},
					password : {
						required : true,
						minlength : 5
					},
					confirm_password : {
						required : true,
						minlength : 5,
						equalTo : "#password"
					},
					email : {
						required : true,
						email : true
					}
				},
				messages : {
					username : {
						required : a + "请输入您的用户名",
						minlength : a + "用户名必须两个字符以上"
					},
					password : {
						required : a + "请输入您的密码",
						minlength : a + "密码必须5个字符以上"
					},
					confirm_password : {
						required : a + "请再次输入密码",
						minlength : a + "密码必须5个字符以上",
						equalTo : a + "两次输入的密码不一致"
					},
					email : a + "请输入您的E-mail"
				},
				 submitHandler:function(form){
					 $(form).ajaxSubmit({
						 	
			            	url:'<%=contextPath%>/sys/user/update',
			            	type:'post',
			            	dataType:"json",
			            	success:function(data){
			            		if(data.code==200){
			            			parent.$('#search').text("reloadGrid");
				            		parent.layer.close(index); //执行关闭
			            		}else{
			            			
			            		}
			            	}
		              }); 
		        }
			});
		});
	</script>
</body>
</html>